"""
@File    :   validate.py
@Time    :   2024/03/28 19:11:41
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   角色相关验证模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, conint

from src.schemas.validate import (
    BaseSearchValidateSchemaMixin,
    BaseValidateSchemaConfigMixin,
)


class RoleCreateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于创建角色的验证模型"""

    name: str = Field(default=..., min_length=1, max_length=50, description="角色名称")
    status: bool = Field(default=True, description="状态")  # (True正常 False停用)
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    show_order: int = Field(
        default=1, min_length=1, max_length=999999999, description="显示顺序"
    )


class RoleUpdateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于修改角色的验证模型
    不可操作管理员角色(在service.py有对应的异步验证方法, 在依赖层调用)
    """

    id: int = Field(default=..., ge=1, description="主键")
    name: str = Field(default=..., min_length=1, max_length=50, description="角色名称")
    status: bool = Field(default=True, description="状态")  # (True正常 False停用)
    remark: str = Field(default="", min_length=1, max_length=300, description="备注")
    show_order: int = Field(
        default=1, min_length=1, max_length=999999999, description="显示顺序"
    )


class RoleUpdateStatusValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于单独修改角色状态的验证模型
    不可操作管理员角色(在service.py有对应的异步验证方法, 在依赖层调用)
    """

    id: int = Field(default=..., ge=1, description="主键")
    status: bool = Field(default=..., description="状态")  # (True正常 False停用)


class RoleAssignMenuPermissionValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于分配角色菜单权限的验证模型"""

    id: int = Field(default=..., ge=1, description="主键")
    menu_ids: list[conint(ge=1)] = Field(
        default_factory=list, description="分配的角色ID列表"
    )


class RoleDeleteValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于删除角色的验证模型
    不可操作管理员角色(在service.py有对应的异步验证方法, 在依赖层调用)
    """

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需删除的主键列表"
    )


class RoleListSearchValidateSchema(BaseModel, BaseSearchValidateSchemaMixin):
    """用于查询角色列表的验证模型"""

    name: str | None = Field(
        default=None,
        description="角色名称",
        min_length=1,
        max_length=50,
        json_schema_extra={"str_like_search_type": "complete"},
    )
    remark: str | None = Field(
        default=None,
        description="备注",
        min_length=1,
        max_length=300,
        json_schema_extra={"str_like_search_type": "complete"},
    )
    status: bool | None = Field(default=None, description="状态")
    is_admin: bool | None = Field(default=None, description="是否管理员角色")
    create_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="创建时间",
        json_schema_extra={"allow_order": True},
    )
    update_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="修改时间",
        json_schema_extra={"allow_order": True},
    )
    creator_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="创建者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    updater_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="修改者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
